package proxy;

import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;

public class BeanDefinitionBuilderExample {

    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory =
                new DefaultListableBeanFactory();

        BeanDefinitionBuilder b = BeanDefinitionBuilder.rootBeanDefinition(MyBean.class)
                .addPropertyValue("str", "myStringValue");
        b.setAutowireMode(GenericBeanDefinition.AUTOWIRE_BY_NAME);
        beanFactory.registerBeanDefinition("myBean", b.getBeanDefinition());
        BeanDefinitionBuilder hello = BeanDefinitionBuilder.rootBeanDefinition(Hello.class);
        beanFactory.registerBeanDefinition("hello", hello.getBeanDefinition());

        MyBean bean = beanFactory.getBean(MyBean.class);
        bean.doSomething();
    }
}